package com.smart.five.ioc.injection.parameter;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author junrui.wang
 * @create 2018/6/6
 */
public class Test {
    public static void main(String[] args) {
        ApplicationContext ac = new ClassPathXmlApplicationContext("com/smart/five/ioc/injection/parameter/beans.xml");
        //字面值
        Car car = (Car)ac.getBean("car1");
        car.introduce();

        //特殊字符转义
        car = (Car)ac.getBean("car2");
        car.introduce();

        car = (Car)ac.getBean("car3");
        car.introduce();

        //引用其他bean
        Boss boss = (Boss) ac.getBean("boss");
        boss.getCar().introduce();

        //匿名bean
        Boss boss1 = (Boss) ac.getBean("boss1");
        boss1.getCar().introduce();

        //空值
        car = (Car)ac.getBean("car4");
        car.introduce();

        //级联属性
        Boss boss2 = (Boss) ac.getBean("boss2");
        boss2.getCar1().introduce();

        //集合类型属性
        //list 字面值
        Boss boss3 = (Boss) ac.getBean("boss3");
        System.out.println(boss3.getFavorites().size());

        //list 引用bean
        Boss boss4 = (Boss) ac.getBean("boss4");
        System.out.println(boss4.getFavorites().size());

        //Set 字面值
        Boss boss5 = (Boss) ac.getBean("boss5");
        System.out.println(boss5.getSets().size());

        //Map(Spring注入的时候会变成LinkHashMap)
        Boss boss6 = (Boss) ac.getBean("boss6");
        System.out.println(boss6.getMaps().size());

        //properties == Map<String,String>
        Boss boss7 = (Boss) ac.getBean("boss7");
        System.out.println(boss7.getMaps().size());

        //强类型集合，指定了类型Map<String, Integer>
        Boss boss8 = (Boss) ac.getBean("boss8");
        System.out.println(boss8.getMaps().size());

        //集合合并
        Boss childBossMerge = (Boss) ac.getBean("childBossMerge");
        System.out.println(childBossMerge.getMaps().size());

        //集合不合并
        Boss childBossNoMerge = (Boss) ac.getBean("childBossNoMerge");
        System.out.println(childBossNoMerge.getMaps().size());

        //通过Util命名空间配置集合类型的bean
        List list1 = (List) ac.getBean("list1");
        List list2 = (List) ac.getBean("list2");
        Set set1 = (Set) ac.getBean("set1");
        Map map1 = (Map) ac.getBean("map1");



    }
}
